package com.cskaoyan.market.validator;

import com.cskaoyan.market.constrain.LegalSort;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.Arrays;
import java.util.List;

/**
 * @author lixianbiao
 * @since 2024/06/28 19:34
 */
public class LegalSortValidator implements ConstraintValidator<LegalSort,String> {
    private List<String> valueList;

    @Override
    public void initialize(LegalSort constraintAnnotation) {
        this.valueList = Arrays.asList(constraintAnnotation.value());
    }

    @Override
    public boolean isValid(String string, ConstraintValidatorContext constraintValidatorContext) {
        return valueList.contains(string);
    }
}